<template>
  <div id="online">
    <div class="dashboard_title">设备在线</div>
    <div class="content">
      <div class="top">
        <div>
          <div class="text-title">设备在线率</div>
          <div class="text-value">
            {{
              ((deviceData.onlineNumber / deviceData.total) * 100).toFixed(0) +
              '%'
            }}
          </div>
        </div>
      </div>
      <div class="bottom">
        <div>
          <div>
            <div class="text-title icon_5">接入总数</div>
            <div class="text-value">{{ deviceData.total }}</div>
          </div>
        </div>
        <div class="line"></div>
        <div>
          <div>
            <div class="text-title icon_6">在线</div>
            <div
              v-if="deviceData.onlineNumber > 0"
              style="cursor: pointer"
              @click="jumpPage('1')"
            >
              <div class="text-value">
                {{ deviceData.onlineNumber }}
                <RightOutlined style="color: #769db0" />
              </div>
            </div>
            <div class="text-value" v-else>{{ deviceData.onlineNumber }}</div>
          </div>
        </div>
        <div class="line"></div>
        <div>
          <div>
            <div class="text-title icon_6">离线</div>
            <div
              v-if="deviceData.offlineNumber > 0"
              style="cursor: pointer"
              @click="jumpPage('0')"
            >
              <div class="text-value">
                {{ deviceData.offlineNumber }}
                <RightOutlined style="color: #769db0" />
              </div>
            </div>
            <div class="text-value" v-else>{{ deviceData.offlineNumber }}</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import router from '@/router';
import { RightOutlined } from '@ant-design/icons-vue';

const props = defineProps({
  deviceData: {
    type: Object,
    default: {},
  },
});

const jumpPage = (val: any) => {
  router.push({
    path: 'devices/allDevice',
    query: { onlineStatus: val },
  });
};
</script>

<style lang="scss" scoped>
@import './css/index.css';
#online {
  background-image: url('@/assets/images/home_icon1.png');
  background-size: 100% 100%;
  background-position: center;
  background-repeat: no-repeat;
}
</style>
